package com.lwl.service.impl;

import com.lwl.entity.TMenuRole;
import com.lwl.service.TMenuRoleService;
import com.lwl.dao.TMenuRoleMapper;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * (TMenuRole)表服务实现类
 *
 * @author Lei
 * @since 2022-10-26 16:20:02
 */
@Service
public class TMenuRoleServiceImpl implements TMenuRoleService {
   @Autowired
   private TMenuRoleMapper tMenuRoleDao;

   @Override
   public boolean updRoleMenu(Integer rid, String mids) {
//      1、先删除当前角色已经有的权限
      TMenuRole tMenuRole = new TMenuRole();
      tMenuRole.setRid(rid);
      int delete = tMenuRoleDao.delete(tMenuRole);


//       2、增加该角色新的权限
      if (mids!=null){
//         将菜单id的字符串转化为数组
         String[] midsStr = mids.split(",");
         for (String mid : midsStr) {
//            循环遍历给该角色赋值新的权限
            Integer i = Integer.parseInt(mid);
            TMenuRole tMenuRole1 = new TMenuRole(rid, i);
            int insert = tMenuRoleDao.insert(tMenuRole1);
         }
      }
      return delete>0;
   }
}
